﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace game
{
    public class SpaceBox : ModelObject
    {

        public ModelObject HookedNode { get; set; }



        public SpaceBox(Scene scene, ModelUnit model, int layerIndex)
            : base(scene, model, layerIndex)
        {
            model.SetDefaultEffects();
        }

        public override void DrawOpaque(GameTime gameTime)
        {
            foreach (ModelMesh mesh in model.Model.Meshes)
            {
                foreach (BasicEffect effect in mesh.Effects)
                {
                    ShooterGame.Instance.GraphicsDevice.SamplerStates[0].AddressU = TextureAddressMode.Wrap;
                    ShooterGame.Instance.GraphicsDevice.SamplerStates[0].AddressV = TextureAddressMode.Wrap;
                    //effect.FogEnabled = true;
                    effect.FogColor = new Vector3(0.5f);
                    effect.FogEnd = 100000000.0f;
                    effect.PreferPerPixelLighting = true;
                    //effect.VertexColorEnabled = true;
                    //effect.EnableDefaultLighting();
                    effect.World = model.transforms[mesh.ParentBone.Index] * World;
                    effect.View = scene.ActiveCamera.View;
                    effect.Projection = scene.ActiveCamera.Projection;
                }
                mesh.Draw();
            }
        }

        public override void Update(GameTime gameTime)
        {
            World = Matrix.CreateTranslation(HookedNode.Position);
        }

        public void HookOn(ModelObject node)
        {
            HookedNode = node;
        }
    }
}
